package top.shiyiri.webfluxdemo1;

import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import top.shiyiri.webfluxdemo1.bean.User;

import java.util.List;

/**
 * @author Aunean
 * @date 2022/2/19 23:37
 */
public class Client {

    public static void main(String[] args) {
        //调用服务器地址
        WebClient webClient = WebClient.create("http://localhost:50953");

        //根据id查询
        String id = "1";
        User block = webClient.get().uri("/user/{id}", id)
                .accept(MediaType.APPLICATION_JSON)
                .retrieve()
                .bodyToMono(User.class)
                .block();
        System.out.println(block);

        //查询所有
        Flux<User> userFlux = webClient.get().uri("/users").accept(MediaType.APPLICATION_JSON).retrieve()
                .bodyToFlux(User.class);

        userFlux.map(stu -> stu).buffer().doOnNext(System.out::println).blockFirst();
    }
}
